<template>
  <view class="content"  :style="{ paddingTop: statusBarHeight + 'px' }">
    <uni-nav-bar title="库存" background-color="#f7f7f7" fixed :border="false" height="88rpx" left-icon="left" @clickLeft="onClickLeft"
     ></uni-nav-bar>
    <view class="topTag">
      <view class="tag" :class="{ activeTag: active == '0' }" @click="changeTab('0')">供应链</view>
      <view class="tag" :class="{ activeTag: active == '2' }" @click="changeTab('2')">自营标品</view>
      <view class="tag" :class="{ activeTag: active == '1' }" @click="changeTab('1')">非标品</view>
    </view>
    <scroll-view class="scroll-view_H" scroll-y @refresherrefresh="refresherrefreshFn" refresher-enabled="true"
      :show-scrollbar="false" @scrolltolower="lower" :refresher-triggered="triggered" enhanced
      style="height: calc(100% - var(--window-top) - 168rpx)">

      <!-- 供应链标品 -->
      <view class="infoCard" v-for="item in scmGoodsList" :key="item.id" v-if="active == '0'">
        <view class="tokenNum">
          <view class="count u-ellipsis goodsname">{{ item.commodityName }}</view>
          <view class="count">{{ item.firstCode }}</view>
        </view>
        <view class="tokenNum">
          <view class="count">库存：{{ item.stockNum }} {{ item.unitName }}</view>
          <view class="count">期初库存：{{ item.initialInventory }} {{ item.unitName }}</view>
        </view>
        <view class="tokenNum">
          <view class="count">零售价：{{ item.storePrice }}元</view>
          <view class="count" v-if="item.productState == '0'">状态：正常</view>
          <view class="count" v-if="item.productState == '1'">状态：停用</view>
          <view class="count" v-if="item.productState == '2'">状态：淘汰</view>
        </view>
      </view>
      <!-- 自营标品 -->
      <view class="infoCard" v-for="item in selfStockList" :key="item.id" v-if="active == '2'">
        <view class="tokenNum">
          <view class="count u-ellipsis goodsname">{{ item.commodityName }}</view>
          <view class="count">{{ item.barCode }}</view>
        </view>
        <view class="tokenNum">
          <view class="count">库存：{{ item.inventoryNum }}</view>
          <view class="count"></view>
        </view>
        <view class="tokenNum">
          <view class="count">零售价：{{ item.storePrice }}元</view>
          <view class="count">进货价：{{ item.buyingPrice }}元</view>
        </view>
      </view>
      <!-- 非标品 -->
      <view class="infoCard" v-for="item in nonstandardStockList" :key="item.id" v-if="active == '1'">
        <view class="tokenNum">
          <view class="count u-ellipsis goodsname">{{ item.name }}</view>
          <view class="count">{{ item.categoryName }}</view>
        </view>
        <view class="tokenNum">
          <view class="count">库存：{{ item.inventoryNum }} KG</view>
          <view class="count">销售单位：KG</view>
        </view>
        <view class="tokenNum">
          <view class="count">零售价：{{ item.storePrice }} 元</view>
          <view class="count">进货价：{{ item.purchasePrice }} 元</view>
        </view>
      </view>
      <uni-load-more :status="loading"
        v-if="scmGoodsList.length > 0 || selfStockList.length > 0 || nonstandardStockList.length > 0"></uni-load-more>
      <view
        style="width: 100%;height: 100%;background-color: #f7f7f7;display: flex;justify-content: center;align-items: center;"
        v-if="scmGoodsList.length == 0 && selfStockList.length == 0 && nonstandardStockList.length == 0">
        <image src="/static/index/nonedata.png" mode="aspectFill" style="width: 400rpx;height: 400rpx;"></image>
      </view>
    </scroll-view>
  </view>
</template>

<script>
import { reqScmStockList, reqNonstandardStockList, reqSelfStockList } from '@/apis/member.js'
export default {
  name: "InventoryInfo",
  data() {
    return {
      active: '0',
      scmGoodsList: [], // 供应链标品
      selfStockList: [], // 自营标品
      nonstandardStockList: [], // 非标品
      page: {
        pageNum: 1,
        pageSize: 15
      },
      triggered: false, // 是否触发下拉刷新
      loading: 'loading', // 是否触发上拉加载
    }
  },
  onLoad() {
    this.reqScmStockList()
  },
  onShow() {
  },
  methods: {
    refresherrefreshFn() {
      this.page.pageNum = 1
      this.triggered = true
      this.scmGoodsList = []
      this.nonstandardStockList = []
      this.selfStockList = []
      this.loading = "loading";
      if (this.active == '0') {
        this.reqScmStockList()
      } else if (this.active == '1') {
        this.reqNonstandardStockList()
      } else if (this.active == '2') {
        this.reqSelfStockList()
      }
    },
    // 供应链 
    async reqScmStockList() {
      const res = await reqScmStockList({ ...this.page })
      if (res.code === 200) {
        this.scmGoodsList = [...this.scmGoodsList, ...res.data.list]
        this.nextPage = res.data.nextPage
        console.log('scmGoodsList:', this.scmGoodsList);
        this.triggered = false
        if (res.data.isLastPage) {
          this.loading = "noMore"
        }
      }
    },
    // 非标品
    async reqNonstandardStockList() {
      const res = await reqNonstandardStockList({ ...this.page })
      if (res.code === 200) {
        this.nonstandardStockList = [...this.nonstandardStockList, ...res.data.list]
        this.nextPage = res.data.nextPage
        console.log('nonstandardStockList:', this.nonstandardStockList);
        this.triggered = false
        if (res.data.isLastPage) {
          this.loading = "noMore"
        }
      }
    },
    // 自营标品
    async reqSelfStockList() {
      const res = await reqSelfStockList({ ...this.page })
      if (res.code === 200) {
        this.selfStockList = [...this.selfStockList, ...res.data.list]
        this.nextPage = res.data.nextPage
        console.log('selfStockList:', this.selfStockList);
        this.triggered = false
        if (res.data.isLastPage) {
          this.loading = "noMore"
        }
      }
    },
    lower() {
      if (this.loading == "noMore") {
        return;
      }
      this.page.pageNum++;
      this.loading = "loading";
      if (this.active == '0') {
        this.reqScmStockList()
      } else if (this.active == '1') {
        this.reqNonstandardStockList()
      } else if (this.active == '2') {
        this.reqSelfStockList()
      }
    },
    changeTab(val) {
      this.page = {
        pageNum: 1,
        pageSize: 15
      }
      this.loading = 'loading'
      this.scmGoodsList = []
      this.nonstandardStockList = []
      this.selfStockList = []
      this.active = val
      if (val == '0') {
        this.reqScmStockList()
      } else if (val == '1') {
        this.reqNonstandardStockList()
      } else if (val == '2') {
        this.reqSelfStockList()
      }
    }
  }
}
</script>
<style>
page {
  background: #f7f7f7;

}
</style>
<style lang="scss" scoped >
.content {
  height: 100vh;
  background-color: #f7f7f7;

}

view {
  box-sizing: border-box;
}

.topTag {
  height: 80rpx;
  display: flex;
  justify-content: space-around;
  align-items: center;
  border-bottom: 1px solid #eee;

  .tag {
    width: 20%;
    height: 70rpx;
    line-height: 70rpx;
    text-align: center;
    font-size: 28rpx;
    color: #999;

    &.activeTag {

      color: $uni-main-bgColor;
      font-weight: bold;
			// box-sizing: border-box;
      border-bottom: 4rpx solid $uni-main-bgColor;
    }
  }
}

.goodsname {
  font-weight: 600;
}

// .infoCard:nth-child(2n+1) {
//   background-color: #d3e3fd;
// }

.infoCard {
  // width: 100%;
  background-color: #edf2fa;
  border-radius: 20rpx;
  margin: 20rpx;
  font-size: 26rpx;
  // margin-bottom: 10rpx;
  padding: 20rpx 30rpx;
  align-items: center;
  height: 180rpx;
  line-height: 50rpx;
  border: 1px solid #d3e3fd;


  .tokenNum {
    display: flex;
    width: 100%;
    justify-content: space-between;

    .count {
      width: 48%;
      padding-left: 20rpx;
    }
  }
}
</style>
